<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 封装冒泡排序函数
        function bubbleSort(arr) {
            // 存储数组长度
            var len = arr.length;

            // 遍历
            for (var i = 0; i < len; i++) {
                for (var j = 0; j < len - i; j++) {
                    if (arr[j] > arr[j + 1]) {
                        // 交换顺序
                        var temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            return arr;
        }

        var arr = [1, 32, 4234, 2525, 34534, 1243, 12, 6, 8, 9];
        console.log(bubbleSort(arr));
    </script>
</body>

</html>